package com.ruoyi.citys.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.citys.domain.TCity;
import com.ruoyi.citys.service.ITCityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区管理Controller
 *
 * @author ruoyi
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/citys/citys")
public class TCityController extends BaseController
{
    @Autowired
    private ITCityService tCityService;

    /**
     * 查询地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('citys:citys:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCity tCity)
    {
        startPage();
        List<TCity> list = tCityService.selectTCityList(tCity);
        return getDataTable(list);
    }

    /**
     * 导出地区管理列表
     */
    @PreAuthorize("@ss.hasPermi('citys:citys:export')")
    @Log(title = "地区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCity tCity)
    {
        List<TCity> list = tCityService.selectTCityList(tCity);
        ExcelUtil<TCity> util = new ExcelUtil<TCity>(TCity.class);
        util.exportExcel(response, list, "地区管理数据");
    }

    /**
     * 获取地区管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('citys:citys:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tCityService.selectTCityById(id));
    }

    /**
     * 新增地区管理
     */
    @PreAuthorize("@ss.hasPermi('citys:citys:add')")
    @Log(title = "地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCity tCity)
    {
        return toAjax(tCityService.insertTCity(tCity));
    }

    /**
     * 修改地区管理
     */
    @PreAuthorize("@ss.hasPermi('citys:citys:edit')")
    @Log(title = "地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCity tCity)
    {
        return toAjax(tCityService.updateTCity(tCity));
    }

    /**
     * 删除地区管理
     */
    @PreAuthorize("@ss.hasPermi('citys:citys:remove')")
    @Log(title = "地区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCityService.deleteTCityByIds(ids));
    }

    @GetMapping("/findAllProvinceNames")
    public AjaxResult findAllProvinceNames()
    {
    	return success(tCityService.findAllProvinceNames());
    }

    @GetMapping("/getCitiesByProvinceName/{provinceName}")
    public AjaxResult getCitiesByProvinceName(@PathVariable String provinceName)
    {
    	return success(tCityService.getCitiesByProvinceName(provinceName));

    }
    @GetMapping("/queryCityByPid/{id}")
    public AjaxResult queryCity(@PathVariable("id") Integer id){
        return success(tCityService.queryCityByPid(id));
    }

}
